{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Re-generate ./baselines folder using ISCE/topsStack ##"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Go to directory ~/insarlab/Galapagos/GalapagosSenDT128/\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20141225/ -b ./baselines/20141213_20141225/20141213_20141225.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150307/ -b ./baselines/20141213_20150307/20141213_20150307.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150319/ -b ./baselines/20141213_20150319/20141213_20150319.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150331/ -b ./baselines/20141213_20150331/20141213_20150331.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150412/ -b ./baselines/20141213_20150412/20141213_20150412.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150424/ -b ./baselines/20141213_20150424/20141213_20150424.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150506/ -b ./baselines/20141213_20150506/20141213_20150506.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150518/ -b ./baselines/20141213_20150518/20141213_20150518.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150530/ -b ./baselines/20141213_20150530/20141213_20150530.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150611/ -b ./baselines/20141213_20150611/20141213_20150611.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150623/ -b ./baselines/20141213_20150623/20141213_20150623.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150717/ -b ./baselines/20141213_20150717/20141213_20150717.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150729/ -b ./baselines/20141213_20150729/20141213_20150729.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150822/ -b ./baselines/20141213_20150822/20141213_20150822.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150903/ -b ./baselines/20141213_20150903/20141213_20150903.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150915/ -b ./baselines/20141213_20150915/20141213_20150915.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20150927/ -b ./baselines/20141213_20150927/20141213_20150927.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20151009/ -b ./baselines/20141213_20151009/20141213_20151009.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20151021/ -b ./baselines/20141213_20151021/20141213_20151021.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20151102/ -b ./baselines/20141213_20151102/20141213_20151102.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20151114/ -b ./baselines/20141213_20151114/20141213_20151114.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20151126/ -b ./baselines/20141213_20151126/20141213_20151126.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20151208/ -b ./baselines/20141213_20151208/20141213_20151208.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20151220/ -b ./baselines/20141213_20151220/20141213_20151220.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160101/ -b ./baselines/20141213_20160101/20141213_20160101.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160113/ -b ./baselines/20141213_20160113/20141213_20160113.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160125/ -b ./baselines/20141213_20160125/20141213_20160125.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160206/ -b ./baselines/20141213_20160206/20141213_20160206.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160218/ -b ./baselines/20141213_20160218/20141213_20160218.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160301/ -b ./baselines/20141213_20160301/20141213_20160301.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160406/ -b ./baselines/20141213_20160406/20141213_20160406.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160418/ -b ./baselines/20141213_20160418/20141213_20160418.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160430/ -b ./baselines/20141213_20160430/20141213_20160430.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160512/ -b ./baselines/20141213_20160512/20141213_20160512.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160524/ -b ./baselines/20141213_20160524/20141213_20160524.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160605/ -b ./baselines/20141213_20160605/20141213_20160605.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160629/ -b ./baselines/20141213_20160629/20141213_20160629.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160711/ -b ./baselines/20141213_20160711/20141213_20160711.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160723/ -b ./baselines/20141213_20160723/20141213_20160723.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160804/ -b ./baselines/20141213_20160804/20141213_20160804.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160816/ -b ./baselines/20141213_20160816/20141213_20160816.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160828/ -b ./baselines/20141213_20160828/20141213_20160828.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160909/ -b ./baselines/20141213_20160909/20141213_20160909.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20160921/ -b ./baselines/20141213_20160921/20141213_20160921.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20161003/ -b ./baselines/20141213_20161003/20141213_20161003.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20161015/ -b ./baselines/20141213_20161015/20141213_20161015.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20161027/ -b ./baselines/20141213_20161027/20141213_20161027.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20161108/ -b ./baselines/20141213_20161108/20141213_20161108.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20161120/ -b ./baselines/20141213_20161120/20141213_20161120.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20161202/ -b ./baselines/20141213_20161202/20141213_20161202.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20161214/ -b ./baselines/20141213_20161214/20141213_20161214.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20161226/ -b ./baselines/20141213_20161226/20141213_20161226.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170107/ -b ./baselines/20141213_20170107/20141213_20170107.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170119/ -b ./baselines/20141213_20170119/20141213_20170119.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170131/ -b ./baselines/20141213_20170131/20141213_20170131.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170212/ -b ./baselines/20141213_20170212/20141213_20170212.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170224/ -b ./baselines/20141213_20170224/20141213_20170224.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170308/ -b ./baselines/20141213_20170308/20141213_20170308.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170320/ -b ./baselines/20141213_20170320/20141213_20170320.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170401/ -b ./baselines/20141213_20170401/20141213_20170401.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170413/ -b ./baselines/20141213_20170413/20141213_20170413.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170425/ -b ./baselines/20141213_20170425/20141213_20170425.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170507/ -b ./baselines/20141213_20170507/20141213_20170507.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170519/ -b ./baselines/20141213_20170519/20141213_20170519.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170531/ -b ./baselines/20141213_20170531/20141213_20170531.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170612/ -b ./baselines/20141213_20170612/20141213_20170612.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170624/ -b ./baselines/20141213_20170624/20141213_20170624.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170706/ -b ./baselines/20141213_20170706/20141213_20170706.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170718/ -b ./baselines/20141213_20170718/20141213_20170718.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170730/ -b ./baselines/20141213_20170730/20141213_20170730.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170811/ -b ./baselines/20141213_20170811/20141213_20170811.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170823/ -b ./baselines/20141213_20170823/20141213_20170823.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170904/ -b ./baselines/20141213_20170904/20141213_20170904.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170916/ -b ./baselines/20141213_20170916/20141213_20170916.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20170928/ -b ./baselines/20141213_20170928/20141213_20170928.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20171010/ -b ./baselines/20141213_20171010/20141213_20171010.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20171022/ -b ./baselines/20141213_20171022/20141213_20171022.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20171103/ -b ./baselines/20141213_20171103/20141213_20171103.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20171115/ -b ./baselines/20141213_20171115/20141213_20171115.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20171127/ -b ./baselines/20141213_20171127/20141213_20171127.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20171209/ -b ./baselines/20141213_20171209/20141213_20171209.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20171221/ -b ./baselines/20141213_20171221/20141213_20171221.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180102/ -b ./baselines/20141213_20180102/20141213_20180102.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180114/ -b ./baselines/20141213_20180114/20141213_20180114.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180126/ -b ./baselines/20141213_20180126/20141213_20180126.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180207/ -b ./baselines/20141213_20180207/20141213_20180207.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180219/ -b ./baselines/20141213_20180219/20141213_20180219.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180303/ -b ./baselines/20141213_20180303/20141213_20180303.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180315/ -b ./baselines/20141213_20180315/20141213_20180315.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180327/ -b ./baselines/20141213_20180327/20141213_20180327.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180408/ -b ./baselines/20141213_20180408/20141213_20180408.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180420/ -b ./baselines/20141213_20180420/20141213_20180420.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180502/ -b ./baselines/20141213_20180502/20141213_20180502.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180514/ -b ./baselines/20141213_20180514/20141213_20180514.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180526/ -b ./baselines/20141213_20180526/20141213_20180526.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180607/ -b ./baselines/20141213_20180607/20141213_20180607.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180619/ -b ./baselines/20141213_20180619/20141213_20180619.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180701/ -b ./baselines/20141213_20180701/20141213_20180701.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180707/ -b ./baselines/20141213_20180707/20141213_20180707.txt\n",
      "computeBaseline.py -m ./master/ -s ./slaves/20180713/ -b ./baselines/20141213_20180713/20141213_20180713.txt\n"
     ]
    }
   ],
   "source": [
    "## Re-generate ./baselines folder using sentinelStack code from ISCE\n",
    "import os\n",
    "import re\n",
    "import glob\n",
    "\n",
    "work_dir = '~/insarlab/Galapagos/GalapagosSenDT128/'\n",
    "os.chdir(os.path.expanduser(work_dir))\n",
    "print('Go to directory '+work_dir)\n",
    "\n",
    "date_list = sorted([re.findall('\\d{8}', i)[0] for i in glob.glob('merged/SLC/*')])\n",
    "m_date = date_list[0]\n",
    "\n",
    "for i in range(1, len(date_list)):\n",
    "    s_date = date_list[i]\n",
    "    date12 = '{}_{}'.format(m_date, s_date)\n",
    "    cmd = 'computeBaseline.py -m ./master/ -s ./slaves/{}/ -b ./baselines/{}/{}.txt'.format(s_date, date12, date12)\n",
    "    print(cmd)\n",
    "    os.system(cmd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
